<template>
<view>
  <PublicPage class="to-audit" page-name="审核设置" :borderType="true" :showNav="true">
    <view class="auditSettings_layout">
      <view class="setUp_msg_box">
        <view class="setUp_msg_l">
          <view class="copywriting_box1 fw6">成为你的帮卖社群需要审核</view>
          <view class="copywriting_box2">开启会增加成为帮卖的难度，请谨慎开启</view>
        </view>
        <view class="setUp_msg_r">
          <u-switch class="switch_button" active-color="#E44435" inactive-color="#ccc" v-model="switchType"></u-switch>
          <view class="switch_click_box" @click.stop="setIsHelpSellFn"></view>
        </view>
      </view>
    </view>
    <Modal
    :show="shipShow"
    :title="switchType?'是否关闭帮卖审核功能？':'是否开启帮卖审核功能？'"
    :style="'color: #323233;line-height: 44rpx;'"
    claceText='取消'
    :configText="switchType?'关闭':'开启'"
    :content="switchType?'关闭帮卖审核功能后，新的帮卖申请将直接自动通过。审核列表未处理的审核也将全部自动通过。':'开启后会增大其他社群成为您帮卖社群的难度，请谨慎确认'"
    @close="closeModalFn"
    @config="configModalFn"/>
  </PublicPage>
</view>
</template>
<script>
import PublicPage from "@/components/publicPage/index.vue";
import Modal from '@/components/modal/index.vue'
import user from "@/api/user.js"
export default {
  components: { PublicPage, Modal },
  data () {
    return {
      switchType: false,
      shipShow: false,
    }
  },
  computed: {
    userInfo () {
      return this.$store.state.userInfo
    },
  },
  onLoad () {
    this.switchType = this.userInfo.isHelpSellExamine==1?true:false
  },
  methods: {
    closeModalFn () {
      this.shipShow = false
    },
    configModalFn () {
      this.updateHelpSellExamineFn(this.switchType?0:1)
    },
    updateHelpSellExamineFn (tyep) {
      user.updateHelpSellExamine({
        isHelpSellExamine: tyep
      }).then((res)=>{
        if (res.code ==200) {
          this.shipShow = false // 关闭弹窗
          let userInfo = this.$store.state.userInfo
          userInfo = {
            ...userInfo,
            isHelpSellExamine: tyep
          }
          this.$store.commit("USERINFO", userInfo)
          this.switchType = this.userInfo.isHelpSellExamine==1?true:false
        }
      })
    },
    setIsHelpSellFn () {
      this.shipShow = true
      // if (this.switchType) {  // 关闭调用
      //   this.updateHelpSellExamineFn(0)
      // } else { // 开启弹窗
      //   this.shipShow = true
      // }
    }
  }
}
</script>
<style lang="scss" scoped>
.auditSettings_layout {
  width: 100%;
  height: 100%;
  .setUp_msg_box {
    padding: 24rpx 32rpx;
    background-color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .setUp_msg_l {
      font-size: 28rpx;
      line-height: 40rpx;
      .copywriting_box1 {
        color: rgba(0, 0, 0, 0.9);
      }
      .copywriting_box2 {
        margin-top: 8rpx;
        font-size: 24rpx;
        line-height: 32rpx;
        color: rgba(0, 0, 0, 0.6);
      }
    }
    .setUp_msg_r {
      position: relative;
      width: 100rpx;
      height: 52rpx;
      .switch_button {
        width: 100%;
        height: 100%;
      }
      .switch_click_box {
        width: 100rpx;
        height: 52rpx;
        position: absolute;
        left: 0;
        top: 0;
        z-index: 10;
      }
    }
  }
}
</style>